// cheng/pages/share-list/share-list.js
let app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    page:1,
    parmas:null,
    shareList:[],
    pageNext:true,
    info:{}
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (e) {
    console.log(e)
    this.data.parmas = e;
    this.getShareList(e.id)
  },
  getShareList(id){
    let t = this,d=t.data;
    app.request({
      url:getApp().api.siteinfo.apiroot+'live/shareInfoList',
      data:{
        hosId:app.api.siteinfo.hosId2,
        liveId: id,
        page:d.page,
        items:20,
      },
      success(e){
        wx.stopPullDownRefresh();
        if(e.shareList.length){
          d.page++;
          d.shareList.push(...e.shareList);
          d.shareList.sort((a,b)=>(b.count-a.count));
          t.setData({
            info:e,
            shareList:d.shareList,
            pageNext:true
          })
        }else {
          d.page--;
          t.setData({
            info:e,
            pageNext:false
          })
        }
        console.log(e)
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    let d = this.data;
    d.shareList.length=0;
    d.page=1;
    this.getShareList(d.parmas.id);
  },


  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    let d = this.data;
    if(!d.pageNext && d.shareList.length>19) return;
    d.pageNext = false;
    this.getShareList(d.parmas.id);
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    let d = this.data;
    console.log(d)
    return {
      title:d.parmas.title,
      path:'/cheng/pages/live1/live1?id='+d.parmas.id+'&oriToken='+d.parmas.token,
      imageUrl:d.parmas.img
    }
  }
})